<template>
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header height="70px">
      <div class="header-left">
        <div class="Zoomout">
          <i class="el-icon-s-fold" @click="Zoomout"></i>
        </div>
        <div class="Backstage">后台管理系统</div>
      </div>
      <div class="header-right">
        <i class="el-icon-rank"></i>
        <i class="el-icon-bell"></i>
        <el-avatar
          src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
        ></el-avatar>
        <el-dropdown trigger="click">
          <span class="el-dropdown-link"
            >{{ name }}<i class="el-icon-caret-bottom el-icon--right"></i
          ></span>
          <el-dropdown-menu slot="dropdown" >
            <el-dropdown-item>项目仓库</el-dropdown-item>
            <el-dropdown-item @click="out()">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <!-- 左侧导航 -->
    <el-container class="container">
      <el-aside :width="isZoomout ? '65px' : ' 250px'">
        <el-col :span="24">
          <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            background-color="#324157  "
            text-color="#BFCBD9"
            active-text-color="#20A0FF"
            unique-opened
            :collapse="isZoomout"
            :collapse-transition="false"
            :router="true"
          >
            <el-menu-item index="Welcome" v-if="isShowMenu('Welcome')">
              <i class="el-icon-s-home"></i>
              <span slot="title">系统首页</span>
            </el-menu-item>
            <el-menu-item index="Foundation" v-if="isShowMenu('Foundation')">
              <i class="el-icon-menu"></i>
              <span slot="title">基础表格</span>
            </el-menu-item>
            <el-menu-item index="Options" v-if="isShowMenu('Options')">
              <i class="el-icon-document"></i>
              <span slot="title">tab选项卡</span>
            </el-menu-item>
            <el-submenu index="Formrelated">
              <template slot="title">
                <i class="el-icon-date"></i>
                <span slot="title">表单相关</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="BasicForm" v-if="isShowMenu('BasicForm')">
                  基本表单</el-menu-item
                >
                <el-submenu index="Three-level">
                  <template slot="title">三级菜单</template>
                  <el-menu-item index="RichTextEditor" v-if="isShowMenu('RichTextEditor')"
                    >富文本编辑器</el-menu-item
                  >
                  <el-menu-item index="markdown" v-if="isShowMenu('markdown')"
                    >markdown编辑器</el-menu-item
                  >
                </el-submenu>
                <el-menu-item index="Fileupload" v-if="isShowMenu('Fileupload')"
                  >文件上传</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
            <el-menu-item index="Customicon" v-if="isShowMenu('Customicon')">
              <i class="el-icon-picture"></i>
              <span slot="title">自定义图标</span>
            </el-menu-item>
            <el-menu-item index="Schartchart" v-if="isShowMenu('Schartchart')">
              <i class="el-icon-pie-chart"></i>
              <span slot="title">schart图表</span>
            </el-menu-item>
            <el-submenu index="DragTheComponent">
              <template slot="title">
                <i class="el-icon-rank"></i>
                <span slot="title">拖拽组件</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  index="DragTheList"
                  v-if="isShowMenu('DragTheList')"
                  >拖拽列表</el-menu-item
                >
                <el-menu-item
                  index="DragBulletFrame"
                  v-if="isShowMenu('DragBulletFrame')"
                  >拖拽弹框</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
            <el-menu-item
              index="internationalization"
              v-if="isShowMenu('internationalization')"
            >
              <i class="el-icon-basketball"></i>
              <span slot="title">国际化功能</span>
            </el-menu-item>
            <el-submenu index="ErrorHandling">
              <template slot="title">
                <i class="el-icon-warning-outline"></i>
                <span slot="title">错误处理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="Permission" v-if="isShowMenu('Permission')"
                  >权限测试</el-menu-item
                >
                <el-menu-item index="Abnormal" v-if="isShowMenu('Abnormal')"
                  >404页面</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
            <el-menu-item index="Support" v-if="isShowMenu('Support')">
              <i class="el-icon-s-finance"></i>
              <span slot="title">支持作者</span>
            </el-menu-item>
          </el-menu>
        </el-col>
      </el-aside>
      <!-- 内容 -->
      <el-main>
        <router-view :a="this.name"></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      isZoomout: false,
      name: "",
    };
  },

  created() {
    let Username = sessionStorage.getItem("vuelogin");
    this.name = JSON.parse(Username)[0].name;
    this.$store.commit("getname", this.name);

    // for(let i=0; i<Username.length;i++){

    // }
    // Username.map((element) => {
    //   this.name=element[0].name

    // });
    // console.log(this.name)
  },

  methods: {
    isShowMenu(path) {
      console.log(path);
      let houpaths = JSON.parse(sessionStorage.getItem("vuelogin"));
      return houpaths.some((route) => route.path == path);
    },

    Zoomout() {
      this.isZoomout = !this.isZoomout;
    },
    out() {
      console.log(1);
      sessionStorage.removeItem("vuelogin");
      this.$router.push("/login");
    },
  },
};
</script>

<style scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #242f42;
}
.el-header .header-left {
  width: auto;
  height: 100%;
  float: left;
}
.el-header .header-right {
  width: 220px;
  height: 100%;
  float: right;
  display: flex;
  justify-content: space-evenly;
  padding-right: 40px;
}
.el-header .header-right i {
  font-size: 22px;
  color: #e9eef3;
  line-height: 70px;
  margin-right: 6px;
}
.header-right .el-avatar {
  margin: auto;
}
.el-header .Zoomout {
  height: 100%;
  width: 22px;
  float: left;
  padding: 0 21px;

  line-height: 70px;
}
.Zoomout i {
  font-size: 22px;
  color: #e9eef3;
  cursor: pointer;
  line-height: 70px;
}
.el-header .Backstage {
  height: 100%;
  width: 250px;
  float: left;
  font-size: 30px;
  color: #e9eef3;
  line-height: 70px;
}
.el-aside {
  background-color: #324157;
}
.el-menu {
  border-right: none;
}
.el-main {
  padding: 0px;
  /* margin-bottom: 30px; */
  background-color: #e9eef3;
  /* height: calc(100% - 70px); */
  overflow: auto;
}
.main-top {
  /* height: calc(100% - 70px); */
  overflow: auto;
}
.container {
  height: calc(100% - 70px);
}
</style>

